package com.zxkj.commonpatrol.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.base.BaseViewModel;
import com.czy.basecommon.utils.base.StateLiveData;
import com.jeremyliao.liveeventbus.LiveEventBus;
import com.zxkj.commonpatrol.model.entity.SubAlarmLogHistory;
import com.zxkj.commonpatrol.model.entity.SubAlarmLogHistorys;
import com.zxkj.commonpatrol.model.post.PostLogInfo;
import com.zxkj.commonpatrol.model.response.AlarmIdBean;
import com.zxkj.commonpatrol.model.response.MediaInfoResponse;
import com.zxkj.commonpatrol.repoisity.AddCheckPointRepoisity;
import com.zxkj.commonpatrol.repoisity.AddExceptionRepoisity;

import java.util.List;

public class AddExceptionViewModel extends BaseViewModel<AddExceptionRepoisity> {
    public ObservableField<String> descr=new ObservableField<>();

    public StateLiveData<String> AlarmId=new StateLiveData<>();

    public StateLiveData<Object> Checked=new StateLiveData<>();
    public StateLiveData<SubAlarmLogHistorys> mData=new StateLiveData<>();
    public AddExceptionViewModel(@NonNull Application application) {
        super(application);
    }


    /**
     * 上传报警图片
     * @param AlarmId 上传报警记录Api返回AlarmId
     * @param GroupId 照片所属媒体组1/媒体组2
     * @param Index   照片在媒体组中的位置索引
     */
    public void uploadPhoto(String path, String AlarmId, int GroupId, int Index,int Type) {
        mRepository.uploadPhoto(path, AlarmId, GroupId, Index,Type, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {

            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {

            }
        });
    }





    /**
     * 上传报警语音
     *
     * @param AlarmId 上传报警记录Api返回AlarmId
     * @param GroupId 语音所属媒体组1/媒体组2
     * @param Index   语音在媒体组中的位置索引
     */
    public void uploadVoice(String path, String AlarmId, int GroupId, int Index,int Type) {
        mRepository.uploadAlarmVoice(path, AlarmId, GroupId, Index,Type, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {

            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {

            }
        });
    }

    /**
     * 上传报警视频
     *
     * @param AlarmId 上传报警记录Api返回AlarmId
     * @param GroupId 视频所属媒体组1/媒体组2
     * @param Index   视频在媒体组中的位置索引
     */
    public void uploadVedio(String path, String AlarmId, int GroupId, int Index,int Type) {
        mRepository.uploadAlarmVoice(path, AlarmId, GroupId, Index,Type, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {

            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {

            }
        });
    }






    /**
     *上传报警记录
     * @param logId 对应点击按钮是上级LogInfo的返回值
     * @param
     */
    public void uploadAlarmLog(String logId,int Type){

        if (Type==0){
            mRepository.uploadAlarmLog(logId, descr.get(), new BaseRepository.MyBaseDataCallBack() {
                @Override
                public void onDataSuccessCallBack(Object o) {
                    String alarmId = (String) o;
                    AlarmId.postSuccess(alarmId);
                    //發消息
                    LiveEventBus.get("EventDeciveList").post("1");
                }

                @Override
                public void onDataFailCallBack(Object o, Object t1) {
                    AlarmId.postFailure(404,(String)t1);
                }
            });
        }else{
            mRepository.uploadUnAlarmLog(logId, descr.get(), new BaseRepository.MyBaseDataCallBack() {
                @Override
                public void onDataSuccessCallBack(Object o) {
                    String alarmId = (String) o;
                    AlarmId.postSuccess(alarmId);
                }

                @Override
                public void onDataFailCallBack(Object o, Object t1) {
                    AlarmId.postFailure(404,(String)t1);
                }
            });
        }



    }



    //获取子问题的历史详情

    public void getHistroy(String id){
        mRepository.getHistoryData(id, new BaseRepository.MyBaseDataCallBack<SubAlarmLogHistorys>() {
            @Override
            public void onDataSuccessCallBack(SubAlarmLogHistorys subAlarmLogHistories) {

                if (subAlarmLogHistories!=null){
                    mData.postSuccess(subAlarmLogHistories);
                }

            }

            @Override
            public void onDataFailCallBack(SubAlarmLogHistorys subAlarmLogHistories, SubAlarmLogHistorys t1) {
                   mData.postFailure(404,"");
            }
        });

    }

    public  void Check(String  id){
        mRepository.getFixException(id, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                Checked.postSuccess(o);
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                Checked.postFailure(404,"");
            }
        });
    }

}
